﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RuleOfReady.Core.DomainModels.Tiles;

namespace RuleOfReady.Core.DomainModels.Sets
{
    /// <summary>
    /// Object for storing a Mahjong Triple or Triplet (Chinese: 'Pung', Japanese: 'Kōtsu')  
    /// A Triple is 3 identical tiles (eg. 4d 4d 4d)
    /// This is the only set in Mahjong that is both Complete and has a waiting tile,
    /// which would turn the triple into a quad.
    /// </summary>
    public class MahjongTriple : MahjongPossibleSet
    {

        #region Public Properties (read-only)

        /// <summary>
        /// (MahjongPossibleSet) Tiles that make up the triple
        /// </summary>
        public override IEnumerable<MahjongTile> Tiles { get; protected set; }

        /// <summary>
        /// (MahjongPossibleSet) Tiles waited that can add to this set
        /// </summary>
        public override IEnumerable<MahjongTile> WaitingTiles { get; protected set; }

        /// <summary>
        /// (MahjongPossibleSet) Flag: whether this possible set represents a complete set (true)
        /// </summary>
        public override bool CompletedSet { get; protected set; }

        #endregion

        #region Constructor

        /// <summary>
        /// Create a new Triple set
        /// </summary>
        /// <param name="tile">the Mahjong Tile that this triple is made of</param>
        public MahjongTriple(MahjongTile tile)
        {
            this.Tiles = Enumerable.Repeat(tile, 3);
            this.WaitingTiles = new[] { tile };
            this.CompletedSet = true;
        }

        #endregion

        #region Public Methods

        /// <summary>
        /// (MahjongPossibleSet) Creates a new Quad from this triple set and a given identical tile
        /// </summary>
        /// <param name="addTile">tile to add</param>
        /// <returns>the new Quad, or null if the given tile wasn't identical</returns>
        public override MahjongPossibleSet Add(MahjongTile addTile)
        {
            if (this.WaitingTiles.Contains(addTile))
                return new MahjongQuad(this.Tiles.First());
            else
                return null;
        }

        #endregion

    }
}
